/*********************************
                     客户端
					 **********************************/
					 /*加载库文件*/
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"WS2_32.lib")

int main(int argc, char*argv[])
{
	/*加载winsock文件*/
	WSADATA wsaData;
	WORD sockVersion = MAKEWORD(2, 0);
	::WSAStartup(sockVersion, &wsaData);

	SOCKET s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	/*创建服务器端的套接字，三个参数分别代表 使用TCP/IP;传输过程使用TCP;不适用其他特殊协议*/

	if (s == INVALID_SOCKET)
	{
		printf("Failed socket()\n");
		::WSACleanup();
		system("pause");
	}

	/*socket中装入地址信息*/
	sockaddr_in servAddr;
	servAddr.sin_family = AF_INET;
	servAddr.sin_port = htons(13); /*接收服务器13端口号*/
	servAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");/*本地IP地址为127.0.0.1*/

														   /*连接服务器*/
	if (::connect(s, (sockaddr*)&servAddr, sizeof(servAddr)) == -1)
	{
		printf("Failed connect()\n");
		::WSACleanup();
		system("pause");
	}

	/*接收数据并打印到屏幕上*/
	char buff[256];
	int nRecv = ::recv(s, buff, 256, 0);
	if (nRecv>0)
	{
		buff[nRecv] = '\0';
		printf("客户端IP：%s\r\n\n", "127.0.0.1");
		printf("接收到数据：%s\n", buff);
		printf("服务器实现者学号：20191326\n");
		system("pause");
	}
}